/*
 * ========THE SOLMIX PROJECT=====================================
 *
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * http://www.gnu.org/licenses/ 
 * or see the FSF site: http://www.fsf.org. 
 */

package org.solmix.fmk.config;

import java.util.List;
import java.util.Map;
import java.util.Properties;

import org.osgi.framework.BundleContext;
import org.solmix.commons.collections.DataTypeMap;
import org.solmix.fmk.config.impl.Module;

/**
 * 
 * @version $Id$
 */
public interface ConfigRealm
{

    List<ConfigurationEntry> getEntries();

    int getRank();

    void setRank(int rank);

    String getName();

    void setName(String name);

    List<Module> getModules();

    void setModules(List<Module> modules);

    BundleContext getBundleContext();

    void setBundleContext(BundleContext bundleContext);

    /**
     * get a subset of configuration by prefix.
     * 
     * @param key
     * @return
     */
    DataTypeMap getConfigBlock(String key);

    /**
     * get a subset of configuration by module name.
     * 
     * @param key
     * @return
     */
    DataTypeMap getModuleConfig(String key);

    /**
     * @param key
     * @return
     */
    DataTypeMap getSubtree(String key);

    /**
     * return config as Properties data structure.
     * 
     * @return
     */
    Properties asProperties();

    boolean put(String key, Object value);

    void putAll(Map t);

    boolean remove(String key);

    /**
     * return String value .just for convenience
     * 
     * @param key
     * @param defaultValue
     * @return
     */
    String getString(String key, String defaultValue);

    /**
     * clear configuration cache.
     * <p>
     * NOTE : if not use cache construct set the method to do nothing
     */
    void clearCache();

    /**
     * do nothing .the function is provided by OSGI Configuration management service.
     * <p>
     * for karaf OSGI runtime ,the command is :config:edit,config:prodel,config:update.
     * 
     * @param properties
     * @throws Exception
     */
    void deleteProperties(List properties) throws Exception;

    /**
     * do nothing .the function is provided by OSGI Configuration management service.
     * <p>
     * for karaf OSGI runtime ,the command is :config:edit,config:prodel,config:update.
     */
    void deleteProperty(String key) throws Exception;

    /**
     * do nothing .the function is provided by OSGI Configuration management service.
     * <p>
     * for karaf OSGI runtime ,the command is :config:edit,config:prodel,config:update.
     */
    void deleteProperties(List properties, String propertyFile) throws Exception;

    /**
     * do nothing .the function is provided by OSGI Configuration management service.
     * <p>
     * for karaf OSGI runtime ,the command is :config:edit,config:prodel,config:update.
     */
    void deleteProperty(String key, String propertyFile) throws Exception;

    /**
     * do nothing .the function is provided by OSGI Configuration management service.
     * <p>
     * for karaf OSGI runtime ,the command is :config:edit,config:update.
     */
    void persistProperties(Map properties, String propertyFile) throws Exception;

    /**
     * do nothing .the function is provided by OSGI Configuration management service.
     * <p>
     * for karaf OSGI runtime ,the command is :config:edit,config:update.
     */
    void persistProperties(Map properties) throws Exception;

    void persistProperty(String key, String value) throws Exception;

    /**
     * do nothing .the function is provided by OSGI Configuration management service.
     * <p>
     * for karaf OSGI runtime ,the command is :config:edit,config:update.
     */
    void persistProperty(String key, String value, String propertyFile) throws Exception;

    /**
     * @param moduleName
     * @return
     */
    Map<String, Object> getLocalConfig(String moduleName);
}
